package com.app.micaihu.view.user.usertask;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.base.BaseOldActivity;
import com.app.micaihu.configure.Config;
import com.app.micaihu.manager.UserInforManager;
import com.app.micaihu.view.login.activity.BindPhoneActivity;

/**
 * Created by Guo on 2016/8/25.
 * <p>
 * 作战奖励的 activity
 */
public class TaskRewardBindPhoneActivity extends BaseOldActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addContentView(R.layout.activity_taskrewardbindphone);
    }


    @Override
    protected void onResume() {
        super.onResume();
        initView();
    }

    private void initView() {
        setTitle("绑定手机");
        TextView tvHtmlContent = (TextView) findViewById(R.id.tv_htmlcontent);
        TextView tvHtmlTitle = (TextView) findViewById(R.id.tv_title);
        TextView tvRule = (TextView) findViewById(R.id.tv_rule);
        TextView tvRuleContent = (TextView) findViewById(R.id.tv_rulecontent);
        TextView tvGoTo = (TextView) findViewById(R.id.tv_goto);
        String strTitle = "<font color='#5a9722' >绑定手机即可获得30军功，30金币\n</font><br/>";
        String str1 = "参与方式：<br/>" +
                "1、在我的页面点击头像,进入个人信息页面<br/>" +
                "2、在手机号一栏点击\"绑定手机号\"<br/>";
        String str2 = "规则:<br/>";
        String str3 = "绑定手机号成功，即达到领取奖励的条件。在作战中心页面点击领取按钮即可获得30军功，30金币奖励.<br/>此奖励每个账号有且仅有一次。";
        tvHtmlTitle.setText(Html.fromHtml(strTitle));
        tvHtmlContent.setText(Html.fromHtml(str1));
        tvRule.setText(Html.fromHtml(str2));
        tvRuleContent.setText(Html.fromHtml(str3));

        boolean login = UserInforManager.getInstance().isLogin();
        if (login) {
            if (!UserInforManager.getInstance().getUserInfor().getTask().getMobileBind()) {
                tvGoTo.setEnabled(true);
                tvGoTo.setText(getResources().getString(R.string.task_bindphone));
                tvGoTo.setOnClickListener(this);
            } else {
                tvGoTo.setEnabled(false);
                tvGoTo.setText(getResources().getString(R.string.task_bindedphone));
            }
        } else {
            tvGoTo.setEnabled(false);
            tvGoTo.setText(getResources().getString(R.string.task_bindphone));
        }
    }

    @Override
    public void onClick(View v) {
        if (v == null) return;
        if (v.getId() == R.id.tv_goto) {
            startActivityForResult(new Intent(this, BindPhoneActivity.class), Config.ResultCode.REQUESTCODE_1);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Config.ResultCode.REQUESTCODE_1 && resultCode == RESULT_OK) {
            UserInforManager.getInstance().showLevelDialog(TaskRewardBindPhoneActivity.this);

        }
    }
}
